#include "GameObject.h"

USING_NS_CC;


GameObject::GameObject()
{
	this->type = type;
}


GameItem::GameItem()
{
	this->type = OT_ITEM;
}

GameUser::GameUser(_OBJECT_TYPE type)
{
	this->type = type;
}

void GameUser::init()
{
	status = CHAR_IDLE;
    
	strength = 10;
	stamina = 10;
	health = 10;
	stress = 10;
	speed = 10;
	acceleration = 10;
	weight = 10;
	reflexes = 10;
	jumping_ability = 10;
	intelligence = 10;
	braking = 10;
    
	autorun = true;
}

void GameUser::update(float dt)
{
    update(dt, curSpeed);
    if(curSpeed < 0 ) curSpeed = 0;
}

void GameUser::update(float dt, float &_speed)
{
    
	float speed = dt * _speed;
    
    
	switch( status ) {
        case CHAR_IDLE:
            break;
            
        case	CHAR_READY_START :
            armature->getAnimation()->play("ready");
            armature->getAnimation()->setSpeedScale(1.0f);
            
            status = CHAR_READY;
            break;
        case	CHAR_READY :
            if( !armature->getAnimation()->getIsPlaying() ) {
                status = CHAR_READY_END;
            }
            break;
        case	CHAR_READY_END :
            status = CHAR_RUN_START;
            
            break;
        case	CHAR_WALK_START :
            break;
        case 	CHAR_WALK :
            break;
        case CHAR_WALK_END :
            break;
            
        case	CHAR_RUN_START :
            if( strcmp(armature->getAnimation()->getCurrentMovementID().c_str(), "run")  ) {
                armature->getAnimation()->play("run");
                armature->getAnimation()->setSpeedScale(1.0f);
            }
            status = CHAR_RUN;
            
            if( autorun )
				_speed = 		400.0f;
            
            
            break;
        case	CHAR_RUN :
			armature->getAnimation()->setSpeedScale(speed / 5.0f);
            
            if( _speed > 750.0f ) {
                if( rand() % 2 == 0 ) {
                    
                    armature->getAnimation()->play("breath");
                    armature->getAnimation()->setSpeedScale(1.0f);
                    status = CHAR_BREATH_START;
                    
                }else if( rand() % 2 == 0 ) {
                    armature->getAnimation()->play("falldown2");
                    armature->getAnimation()->setSpeedScale(1.0f);
                    status = CHAR_FALLDOWN_START;
                    
                }
            }
            
            if( autorun )
                if( rand() % 10 < 7 ) {
                    _speed += 		300.0f * dt;
                }
            
            break;
        case	CHAR_BREATH_START :
            _speed = 0;
            armature->getAnimation()->play("breath");
            armature->getAnimation()->setSpeedScale(1.0f);
            
            status = CHAR_BREATH;
            break;
            
        case	CHAR_BREATH :
            if( !armature->getAnimation()->getIsPlaying() ) {
                status = CHAR_BREATH_END;
            }
            break;
            
        case	CHAR_BREATH_END :
            if( autorun )
                status = CHAR_RUN_START;
            else
                status = CHAR_IDLE;
            break;
            
        case	CHAR_FALLDOWN_START :
            armature->getAnimation()->play("falldown2");
            armature->getAnimation()->setSpeedScale(1.0f);
            
            status = CHAR_FALLDOWN;
            break;
            
        case	CHAR_FALLDOWN :
            if( !armature->getAnimation()->getIsPlaying() ) {
                status = CHAR_FALLDOWN_END;
            }
            break;
        case	CHAR_FALLDOWN_END :
            if( autorun )
                status = CHAR_RUN_START;
            else
                status = CHAR_IDLE;
            break;
            
        case	CHAR_RUNJUMP_START :
            if( strcmp(armature->getAnimation()->getCurrentMovementID().c_str(), "run_jump")  ) {
                armature->getAnimation()->play("run_jump");
                armature->getAnimation()->setSpeedScale(1.0f);
                status = CHAR_RUNJUMP;
            }
            break;
            
        case	CHAR_RUNJUMP :
            
			if( !armature->getAnimation()->getIsPlaying() ) {
				status = CHAR_RUNJUMP_END;
				break;
			}
            break;
            
        case	CHAR_RUNJUMP_END :
            status = CHAR_RUN_START;
            break;
            
        default:
            break;
            
	}
    
}

